﻿namespace Sidvall.AuthorizationManager.Net.Services.V1
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
    public sealed partial class AuthorizationContext : global::Sidvall.Data.ServiceDataRowBase, global::Sidvall.AuthorizationManager.Data.IAuthorizationContext
    {
        #region Public Members

        #region Action

        private string _Action;
        partial void OnBeforeActionPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterActionPropertyChanged();
        public string Action
        { 
            get
            {
                return _Action;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _Action = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _Action);
                    OnBeforeActionPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("Action", eventData.Value, true, true);
                        OnAfterActionPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region AuthorizationContextId

        private System.Nullable<int> _AuthorizationContextId;
        partial void OnBeforeAuthorizationContextIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<int>> eventData);
        partial void OnAfterAuthorizationContextIdPropertyChanged();
        public System.Nullable<int> AuthorizationContextId
        { 
            get
            {
                return _AuthorizationContextId;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _AuthorizationContextId = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<System.Nullable<int>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<int>>(value, _AuthorizationContextId);
                    OnBeforeAuthorizationContextIdPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("AuthorizationContextId", eventData.Value, true, true);
                        OnAfterAuthorizationContextIdPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region ClaimType

        private string _ClaimType;
        partial void OnBeforeClaimTypePropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterClaimTypePropertyChanged();
        public string ClaimType
        { 
            get
            {
                return _ClaimType;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _ClaimType = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _ClaimType);
                    OnBeforeClaimTypePropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("ClaimType", eventData.Value, true, true);
                        OnAfterClaimTypePropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region ClaimValue

        private string _ClaimValue;
        partial void OnBeforeClaimValuePropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterClaimValuePropertyChanged();
        public string ClaimValue
        { 
            get
            {
                return _ClaimValue;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _ClaimValue = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _ClaimValue);
                    OnBeforeClaimValuePropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("ClaimValue", eventData.Value, true, true);
                        OnAfterClaimValuePropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region Resource

        private string _Resource;
        partial void OnBeforeResourcePropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterResourcePropertyChanged();
        public string Resource
        { 
            get
            {
                return _Resource;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _Resource = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _Resource);
                    OnBeforeResourcePropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("Resource", eventData.Value, true, true);
                        OnAfterResourcePropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region ResourceItemId

        private string _ResourceItemId;
        partial void OnBeforeResourceItemIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterResourceItemIdPropertyChanged();
        public string ResourceItemId
        { 
            get
            {
                return _ResourceItemId;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _ResourceItemId = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _ResourceItemId);
                    OnBeforeResourceItemIdPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("ResourceItemId", eventData.Value, true, true);
                        OnAfterResourceItemIdPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region SubAction

        private string _SubAction;
        partial void OnBeforeSubActionPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterSubActionPropertyChanged();
        public string SubAction
        { 
            get
            {
                return _SubAction;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _SubAction = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _SubAction);
                    OnBeforeSubActionPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("SubAction", eventData.Value, true, true);
                        OnAfterSubActionPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region UserName

        private string _UserName;
        partial void OnBeforeUserNamePropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterUserNamePropertyChanged();
        public string UserName
        { 
            get
            {
                return _UserName;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _UserName = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _UserName);
                    OnBeforeUserNamePropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("UserName", eventData.Value, true, true);
                        OnAfterUserNamePropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region DataRowContextStorageKey

        protected override string DataRowContextStorageKey
        {
            get
            {
                return global::Sidvall.AuthorizationManager.SystemContextConfig.Current.EntityFacade.AuthorizationContextManager.GetKey(this);
            }
        }

        #endregion
        #region DataRowStateIsDirty

        protected override bool DataRowStateIsDirty
        {
            get
            {
                return global::Sidvall.AuthorizationManager.SystemContextConfig.Current.EntityFacade.AuthorizationContextManager.DataRowStateIsDirty(this);
            }
        }

        #endregion
        #region LoadInstanceField

        public void LoadInstanceField(string fieldName, object value, bool cascade, bool updateState)
        {
            global::Sidvall.AuthorizationManager.SystemContextConfig.Current.EntityFacade.AuthorizationContextManager.LoadInstanceField(this, fieldName, value, cascade, false, updateState);
        }

        #endregion
        #region Copy

        public AuthorizationContext Copy()
        {
            return global::Sidvall.AuthorizationManager.SystemContextConfig.Current.EntityFacade.AuthorizationContextManager.Copy(this);
        }
        public AuthorizationContext Copy(Sidvall.Data.CopySettings settings)
        {
            return global::Sidvall.AuthorizationManager.SystemContextConfig.Current.EntityFacade.AuthorizationContextManager.Copy(this, settings);
        }

        #endregion
        #region Import

        public void Import(global::Sidvall.AuthorizationManager.Data.IAuthorizationContext item)
        {
            global::Sidvall.AuthorizationManager.SystemContextConfig.Current.EntityFacade.AuthorizationContextManager.Import(this, item);
        }
        public void Import(global::Sidvall.AuthorizationManager.Data.IAuthorizationContext item, Sidvall.Data.CopySettings settings)
        {
            global::Sidvall.AuthorizationManager.SystemContextConfig.Current.EntityFacade.AuthorizationContextManager.Import(this, item, settings);
        }

        #endregion
        #region ValidateAsync

        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync()
        {
            return await global::Sidvall.AuthorizationManager.SystemContextConfig.Current.EntityFacade.AuthorizationContextManager.ValidateAsync(this).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync(Sidvall.Data.ValidationSettings settings)
        {
            return await global::Sidvall.AuthorizationManager.SystemContextConfig.Current.EntityFacade.AuthorizationContextManager.ValidateAsync(this, settings).ConfigureAwait(false);
        }

        #endregion
        #region Initialize

        public void Initialize()
        {
            global::Sidvall.AuthorizationManager.SystemContextConfig.Current.EntityFacade.AuthorizationContextManager.Initialize(this);
        }
        public void Initialize(Sidvall.Data.InitializeSettings settings)
        {
            global::Sidvall.AuthorizationManager.SystemContextConfig.Current.EntityFacade.AuthorizationContextManager.Initialize(this, settings);
        }

        #endregion

        #region IAuthorizationContext Members

        string global::Sidvall.AuthorizationManager.Data.IAuthorizationContext.Action
        {
            get
            {
                return this._Action;
            }
            set
            {
                this._Action = value;
            }
        }
        System.Nullable<int> global::Sidvall.AuthorizationManager.Data.IAuthorizationContext.AuthorizationContextId
        {
            get
            {
                return this._AuthorizationContextId;
            }
            set
            {
                this._AuthorizationContextId = value;
            }
        }
        string global::Sidvall.AuthorizationManager.Data.IAuthorizationContext.ClaimType
        {
            get
            {
                return this._ClaimType;
            }
            set
            {
                this._ClaimType = value;
            }
        }
        string global::Sidvall.AuthorizationManager.Data.IAuthorizationContext.ClaimValue
        {
            get
            {
                return this._ClaimValue;
            }
            set
            {
                this._ClaimValue = value;
            }
        }
        string global::Sidvall.AuthorizationManager.Data.IAuthorizationContext.Resource
        {
            get
            {
                return this._Resource;
            }
            set
            {
                this._Resource = value;
            }
        }
        string global::Sidvall.AuthorizationManager.Data.IAuthorizationContext.ResourceItemId
        {
            get
            {
                return this._ResourceItemId;
            }
            set
            {
                this._ResourceItemId = value;
            }
        }
        string global::Sidvall.AuthorizationManager.Data.IAuthorizationContext.SubAction
        {
            get
            {
                return this._SubAction;
            }
            set
            {
                this._SubAction = value;
            }
        }
        string global::Sidvall.AuthorizationManager.Data.IAuthorizationContext.UserName
        {
            get
            {
                return this._UserName;
            }
            set
            {
                this._UserName = value;
            }
        }

        #endregion

        #endregion
        #region Constructors

        public AuthorizationContext()
        {
        }
        public AuthorizationContext(bool initializeDefaultValues)
            : this(initializeDefaultValues, null, Sidvall.Business.BusinessEvents.None)
        {
        }
        public AuthorizationContext(bool initializeDefaultValues, Sidvall.Data.DataRowState? dataRowState, Sidvall.Business.BusinessEvents enabledBusinessEvents)
            : base(dataRowState, enabledBusinessEvents)
        {
            if (initializeDefaultValues)
                global::Sidvall.AuthorizationManager.SystemContextConfig.Current.EntityFacade.AuthorizationContextManager.Initialize(this);
        }

        #endregion
    }
}